
package linuxbox.admin.bean;

import java.util.*;

import linuxbox.BoxStatic;
import linuxbox.util.*;
import linuxbox.admin.logic.*;
import linuxbox.admin.exception.*;

public class UserCtrlHome extends Object {
	private	DbAdapter m_db = null;
	private	boolean m_bTransaction = false;
	
	public UserCtrlHome() {
		m_db = null;
		m_bTransaction = false;
	}
	
	public UserCtrlHome(DbAdapter db) {
		m_db = db;
		m_bTransaction = true;
	}

	public UserCtrlKey create(User user) throws UserCtrlBeanException {
		UserCtrlBean bean = null;
		UserCtrlKey key = null;

		if (m_bTransaction)
			bean = new UserCtrlBean(null, m_db);
		else
			bean = new UserCtrlBean(null);
		key = bean.create(user);

		return key;
	}

	public boolean create(UserCtrlKey pk) {
		UserCtrlBean bean = null;
		boolean result = false;
		try {
			if (m_bTransaction)
				bean = new UserCtrlBean(pk, m_db);
			else
				bean = new UserCtrlBean(pk);
			bean.create(pk);
			result = true;
		} catch(UserCtrlBeanException e) {
			BoxStatic.logger.error("Home.create error: " + e.getMessage() );
			result = false;
		}
		return result;
	}

	public void remove(UserCtrlKey pk) throws UserCtrlBeanException {
		UserCtrlBean bean = null;

		if (m_bTransaction)
			bean = new UserCtrlBean(pk, m_db);
		else
			bean = new UserCtrlBean(pk);
		bean.remove();
	}

	public UserCtrlKey findByKey(UserCtrlKey pk) throws UserCtrlBeanException {
		UserCtrlBean bean = null;
		UserCtrlKey result = null;

		if (m_bTransaction)
			bean = new UserCtrlBean(pk, m_db);
		else
			bean = new UserCtrlBean(pk);
		result = bean.findByKey();

		return result;
	}

	public UserCtrlKey findByLoginID(String loginID) {
		UserCtrlBean bean = null;
		UserCtrlKey result = null;
		try {
			if (m_bTransaction)
				bean = new UserCtrlBean(null, m_db);
			else
				bean = new UserCtrlBean(null);
			result = bean.findByLoginID(loginID);
		} catch(UserCtrlBeanException e) {
			BoxStatic.logger.error("Home.findByLoginID error: " + e.getMessage() );
			result = null;
		}
		return result;
	}

	public List findBySql(String sqlWhere) {
		UserCtrlBean bean = null;
		List result = null;
		try {
			if (m_bTransaction)
				bean = new UserCtrlBean(null, m_db);
			else
				bean = new UserCtrlBean(null);
			
			result = bean.findBySql(sqlWhere);
		} catch(UserCtrlBeanException e) {
			BoxStatic.logger.error("Home.findBySql error: " + e.getMessage() );
			result = null;
		}
		return result;
	}
}